

import java.io.*;

@SuppressWarnings("serial")
public class TextFileHandler extends File {

	BufferedWriter outBuffer;

	String fName;


	public TextFileHandler(String filename,boolean isNewFile)
	{
		super(filename);
		if (filename==null)
			System.out.println("TextFileHandler was created for filename null");
		fName=filename;
		try {
			FileWriter fstream = new FileWriter(filename,!isNewFile);
			outBuffer = new BufferedWriter(fstream);		
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected void finalize() throws Throwable
	{
		outBuffer.close();
		super.finalize(); //not necessary if extending Object.
	}

	public PrintWriter getPrintWriter()
	{
		return new PrintWriter(outBuffer);
	}

	public void write(String st) throws IOException
	{		
		if (st==null)
			throw new IOException("can not write a null string");		
		try {
			outBuffer.write(st);
			outBuffer.newLine();
			outBuffer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public boolean close() throws IOException
	{
			outBuffer.close();
		return true;
	}

}
